package com.wish233.wiliwilisearch.manager;

import com.wish233.wiliwilisearch.domain.enu.SearchType;
import com.wish233.wiliwilisearch.manager.impl.VideoSearchManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;

/**
 * @author WHH
 * searchmanager的注册中心
 */
@Component
@RequiredArgsConstructor
public class SearchManagerRegistry {

    private HashMap<SearchType, SearchManager> searchManagerMap;

    private final VideoSearchManager videoSearchManager;

    @PostConstruct
    public void init() {
        searchManagerMap = new HashMap<>();
        searchManagerMap.put(SearchType.VIDEO, videoSearchManager);
    }

    public SearchManager getSearchManagerByType(SearchType searchType) {
        return searchManagerMap.get(searchType);
    }

    public SearchManager getSearchManagerById(Integer searchId) {
        SearchType searchType = SearchType.getTypeById(searchId);
        return searchManagerMap.get(searchType);
    }


}
